/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;


/**
 *
 * @author Edwin
 */

@Entity
@Table(name = "MOVIE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "getMovieByName", query = "SELECT m from Movie m where lower(m.name) like :name"),
    @NamedQuery(name = "getAll", query = "SELECT m from Movie m"),
    @NamedQuery(name = "Movie.findByCover", query = "SELECT m FROM Movie m WHERE m.cover = :cover"),
    @NamedQuery(name = "Movie.findByGenre", query = "SELECT m FROM Movie m WHERE m.genre = :genre"),
    @NamedQuery(name = "Movie.findByPlotKeywords", query = "SELECT m FROM Movie m WHERE m.plotKeywords = :plotKeywords"),
    @NamedQuery(name = "Movie.findByRating", query = "SELECT m FROM Movie m WHERE m.rating = :rating"),
    @NamedQuery(name = "Movie.findByDuration", query = "SELECT m FROM Movie m WHERE m.duration = :duration"),
    @NamedQuery(name = "Movie.findByAvailableForRental", query = "SELECT m FROM Movie m WHERE m.availableForRental = :availableForRental"),
    @NamedQuery(name = "Movie.findByActor", query = "SELECT m FROM Movie m WHERE m.availableForPurchase = :availableForPurchase"),
    @NamedQuery(name = "Movie.findByAvailableForPurchase", query = "SELECT m FROM Movie m WHERE m.availableForPurchase = :availableForPurchase"),
    //@NamedQuery(name = "Movie.deleteByID", query = "DELETE m FROM Movie WHERE m.id = :id")
})

public class Movie implements Serializable {
    
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="MovieID") //Validar el nombre como llave primaria
    private Long id;
    @Column(name="MovieName")
    private String name;
    @Column(name="MovieYearr")
    private Integer yearr;
    @Column(name="MovieCover")
    private String cover;
    @Column(name="MovieGenre")
    private String genre;
    @Column(name="MoviePlotKeywords")
    private String plotKeywords;
    @Column(name="MovieRating")
    private Float rating;    
    @Column(name="MovieDuration")
    private Float duration;
    @Column(name="MovievailableForRental")
    private Boolean availableForRental;
    @Column(name="MovieAvailableForPurchase")
    private Boolean availableForPurchase;
    @JoinColumn(name="Movie_IDDirector")
    @ManyToOne(cascade= CascadeType.ALL)
    private Director directorEntity;
    @JoinColumn(name="Movie_MovieActor")
    @ManyToOne
    private Actor_Movie_Entity movieActorEntity;
//    @OneToOne(cascade= CascadeType.ALL, mappedBy = "movieEntity")
//    private Soundtrack soundtrackEntity;

    public Movie() {
    }

    public Movie(Long id) {
        this.id=id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getYear() {
        return yearr;
    }

    public void setYear(Integer year) {
        this.yearr = year;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }

    public String getPlotKeywords() {
        return plotKeywords;
    }

    public void setPlotKeywords(String plotKeywords) {
        this.plotKeywords = plotKeywords;
    }

    public Float getRating() {
        return rating;
    }

    public void setRating(Float rating) {
        this.rating = rating;
    }

    public Float getDuration() {
        return duration;
    }

    public void setDuration(Float duration) {
        this.duration = duration;
    }

    public Boolean getAvailableForRental() {
        return availableForRental;
    }

    public void setAvailableForRental(Boolean availableForRental) {
        this.availableForRental = availableForRental;
    }

    public Boolean getAvailableForPurchase() {
        return availableForPurchase;
    }

    public void setAvailableForPurchase(Boolean availableForPurchase) {
        this.availableForPurchase = availableForPurchase;
    }

    
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Movie)) {
            return false;
        }
        Movie other = (Movie) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entitys.MovieEntity[ id=" + id + " ]";
    }
    
}
